package defpackage; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.os.AsyncTask; import android.os.Build; import android.os.Environment; import android.os.StatFs; import android.support.v4.internal.view.SupportMenu; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import cn.wps.moffice_eng.R; import defpackage.fzm; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; /* renamed from: fzs reason: default package */ public final class fzs implements fzp { public static volatile boolean gKM; public static volatile boolean gKN; Runnable eNP; String ego; BroadcastReceiver fGM; czq gKO; czy gKP; HttpURLConnection gKQ; String gKR; String[] gKS; String gKT; fzm gKU; String gKV; String gKW; File[] gKX; float gKY; private float gKZ; private boolean gLa; boolean gLb; private long gLc; private String gLd; Runnable gLe; boolean gLf; private boolean gLg; czq gLh; fzq gLi; boolean gLj = false; Activity mActivity; /* renamed from: fzs$a */ class a implements fzm.a { private a() { } /* synthetic */ a(fzs fzs, byte b) { this(); } @Override // defpackage.fzm.a public final void a(czq czq) { czq.dismiss(); } @Override // defpackage.fzm.a public final void b(czq czq) { czq.dismiss(); } public final void onClick(DialogInterface dialogInterface, int i) { switch (i) { case -2: break; default: return; case -1: fzs.this.mActivity.startActivity(new Intent("android.settings.WIFI_SETTINGS")); break; } dialogInterface.dismiss(); } } /* renamed from: fzs$b */ class b extends AsyncTask<String, Integer, Boolean> { private b() { } /* synthetic */ b(fzs fzs, byte b) { this(); } /* access modifiers changed from: private */ /* JADX WARNING: Removed duplicated region for block: B:38:0x0101 A[SYNTHETIC, Splitter:B:38:0x0101] */ /* JADX WARNING: Removed duplicated region for block: B:41:0x0106 A[SYNTHETIC, Splitter:B:41:0x0106] */ /* JADX WARNING: Removed duplicated region for block: B:60:0x016e A[SYNTHETIC, Splitter:B:60:0x016e] */ /* JADX WARNING: Removed duplicated region for block: B:63:0x0173 A[SYNTHETIC, Splitter:B:63:0x0173] */ /* renamed from: o */ public Boolean doInBackground(String... strArr) { InputStream inputStream; InputStream inputStream2; int read; FileOutputStream fileOutputStream = null; fzs.gKN = true; fzs.this.bKo(); fzs.this.bKm(); fzs.this.gKR = fzs.this.gKV + File.separator + fzs.this.gKW; try { fzs.this.gKQ = (HttpURLConnection) new URL(strArr[0]).openConnection(); fzs.this.gKQ.setConnectTimeout(10000); fzs.this.gKQ.setReadTimeout(15000); inputStream2 = fzs.this.gKQ.getInputStream(); try { float contentLength = (float) fzs.this.gKQ.getContentLength(); long j = (long) ((int) contentLength); StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath()); if (!((Build.VERSION.SDK_INT >= 18 ? statFs.getAvailableBytes() : ((long) statFs.getBlockSize()) * ((long) statFs.getAvailableBlocks())) > j)) { fzs.this.gLb = false; if (inputStream2 != null) { try { inputStream2.close(); } catch (Exception e) { e.printStackTrace(); } } try { fzs.this.gKQ.disconnect(); return false; } catch (Exception e2) { e2.printStackTrace(); return false; } } else { FileOutputStream fileOutputStream2 = new FileOutputStream(fzs.this.gKR); try { byte[] bArr = new byte[1024]; float f = 0.0f; while (!fzs.gKM && (read = inputStream2.read(bArr)) != -1) { fileOutputStream2.write(bArr, 0, read); if (!fzs.this.gLf) { f += (float) read; publishProgress(Integer.valueOf((int) ((f / contentLength) * 100.0f))); } } if (!fzs.gKM) { fzs.a(fzs.this, new File(fzs.this.gKR)); fzs.this.gLi.cz(fzs.this.gKY); fzs.this.gLi.ae(fzs.this.gKX[0].length()); } else { fzs.this.gLi.uG("unDownload"); } if (inputStream2 != null) { try { inputStream2.close(); } catch (Exception e3) { e3.printStackTrace(); } } try { fileOutputStream2.close(); fzs.this.gKQ.disconnect(); return true; } catch (Exception e4) { e4.printStackTrace(); return true; } } catch (Exception e5) { e = e5; fileOutputStream = fileOutputStream2; inputStream = inputStream2; try { fzs.this.gLi.uG("unDownload"); e.printStackTrace(); if (inputStream != null) { } if (fileOutputStream != null) { } fzs.this.gKQ.disconnect(); return false; } catch (Throwable th) { th = th; inputStream2 = inputStream; if (inputStream2 != null) { } if (fileOutputStream != null) { } fzs.this.gKQ.disconnect(); throw th; } } catch (Throwable th2) { th = th2; fileOutputStream = fileOutputStream2; if (inputStream2 != null) { } if (fileOutputStream != null) { } fzs.this.gKQ.disconnect(); throw th; } } } catch (Exception e6) { e = e6; inputStream = inputStream2; fzs.this.gLi.uG("unDownload"); e.printStackTrace(); if (inputStream != null) { try { inputStream.close(); } catch (Exception e7) { e7.printStackTrace(); } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (Exception e8) { e8.printStackTrace(); return false; } } fzs.this.gKQ.disconnect(); return false; } catch (Throwable th3) { th = th3; if (inputStream2 != null) { try { inputStream2.close(); } catch (Exception e9) { e9.printStackTrace(); } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (Exception e10) { e10.printStackTrace(); throw th; } } fzs.this.gKQ.disconnect(); throw th; } } catch (Exception e11) { e = e11; inputStream = null; fzs.this.gLi.uG("unDownload"); e.printStackTrace(); if (inputStream != null) { } if (fileOutputStream != null) { } fzs.this.gKQ.disconnect(); return false; } catch (Throwable th4) { th = th4; inputStream2 = null; if (inputStream2 != null) { } if (fileOutputStream != null) { } fzs.this.gKQ.disconnect(); throw th; } } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ /* access modifiers changed from: protected */ @Override // android.os.AsyncTask public final /* synthetic */ void onPostExecute(Boolean bool) { Boolean bool2 = bool; fzs.gKN = false; fzs.this.gKP.axW(); fzs fzs = fzs.this; File file = new File(fzs.this.gKR); if (file != null && file.exists()) { file.delete(); } if (!bool2.booleanValue() || fzs.gKM) { fzs.this.mActivity.sendBroadcast(new Intent("TTSPLUGIN_DOWNLOAD_COMPLETE_ERROR_ACTION")); fzs.this.bKo(); fzs.this.gLi.uG("unDownload"); if (!fzs.this.gLb) { new czq(fzs.this.mActivity).setMessage(R.string.public_text_to_speech_download_plugin_noenough_space).setPositiveButton(R.string.public_ok, new DialogInterface.OnClickListener() { /* class defpackage.fzs.b.AnonymousClass1 */ public final void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).show(); } else if (fzs.gKM) { } else { if (fzs.this.gLf) { gcq.ch("yuyin_error", fzs.this.ego); lvg.d(fzs.this.mActivity, R.string.home_account_setting_netword_error, 0); return; } lvg.d(fzs.this.mActivity, R.string.public_text_to_speech_download_plugin_network_error, 0); } } else { fzs.this.mActivity.sendBroadcast(new Intent("TTSPLUGIN_DOWNLOAD_COMPLETE_ACTION")); if (fzs.this.eNP != null) { fzs.this.eNP.run(); } while (!"downloaded".equals(fzs.this.gLi.bKh())) { fzs.this.gLi.uG("downloaded"); fzs.this.gLi.bKe(); } dwp.km("writer_yuyin_download_complete"); fzs fzs2 = fzs.this; fzs2.mActivity = null; fzs2.gKO = null; fzs2.gKQ = null; fzs2.gKS = null; fzs2.gKT = null; fzs2.gKU = null; } } /* access modifiers changed from: protected */ public final void onPreExecute() { } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object[]] */ /* access modifiers changed from: protected */ @Override // android.os.AsyncTask public final /* synthetic */ void onProgressUpdate(Integer[] numArr) { Integer[] numArr2 = numArr; if (!fzs.this.gLf) { fzs.this.gKP.nW(numArr2[0].intValue()); } } } /* renamed from: fzs$c */ class c implements DialogInterface.OnClickListener { private c() { } /* synthetic */ c(fzs fzs, byte b) { this(); } public final void onClick(DialogInterface dialogInterface, int i) { switch (i) { case -2: dialogInterface.dismiss(); return; case -1: dialogInterface.dismiss(); dwp.km("writer_yuyin_download_ok"); if (!lwd.hu(fzs.this.mActivity) && !fzs.this.gLf) { fzs.this.gKU = new fzm(fzs.this.mActivity, 0); fzs.this.gKU.gKB = new a(fzs.this, (byte) 0); fzs.this.gKU.initDialog(); fzs.this.gKU.show(); return; } else if (fzs.this.bKj()) { if (!fzs.this.gLf) { lvg.a(fzs.this.mActivity, fzs.this.mActivity.getResources().getString(R.string.public_text_to_speech_download_plugin_is_downloading), 1000); return; } fzs.this.bKn(); return; } else if (!fzs.this.bKk()) { fzs fzs = fzs.this; fzs.gLi.uG("downloading"); fzs.gKP = new czy(fzs.mActivity, true, new View.OnClickListener() { /* class defpackage.fzs.AnonymousClass1 */ public final void onClick(View view) { fzs.gKM = true; } }); fzs.gKP.setCanAutoDismiss(false); fzs.gKP.nV(R.string.public_text_to_speech_download_plugin_obtain_file); fzs.gKP.nW(0); if (!fzs.gLf) { fzs.gKP.show(); } fzs.bKn(); new b(fzs, (byte) 0).execute(fzs.gKT); return; } else if (fzs.this.eNP != null) { fzs.this.eNP.run(); return; } else { return; } default: return; } } } public fzs(Activity activity, fzq fzq, Runnable runnable, Runnable runnable2, boolean z, boolean z2, String str) { this.gLf = z; this.gLg = z2; this.ego = str; this.mActivity = activity; this.eNP = runnable; this.gLe = runnable2; this.gLi = fzq; this.gLb = true; gKN = false; this.gLa = false; gKM = false; this.gKW = this.gLi.bKc(); this.gKY = this.gLi.bKd(); this.gLi.bKe(); this.gKZ = fzq.bKi(); this.gKV = lwt.IO(this.mActivity.getApplicationInfo().dataDir); this.gKS = fzq.bKf(); this.gKX = new File[this.gKS.length]; for (int i = 0; i < this.gKS.length; i++) { this.gKX[i] = lwt.p(this.gKS[i], this.mActivity.getApplicationInfo().dataDir, true); } this.gKT = "http://cloudservice15.kingsoft-office-service.com/plugins/" + this.gKW; } static /* synthetic */ void a(fzs fzs, File file) throws Exception { ZipFile zipFile = new ZipFile(file); ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(file)); while (true) { ZipEntry nextEntry = zipInputStream.getNextEntry(); if (nextEntry != null) { File file2 = new File(fzs.gKV + File.separator + nextEntry.getName()); if (!file2.getParentFile().exists()) { file2.getParentFile().mkdirs(); } byte[] bArr = new byte[1024]; FileOutputStream fileOutputStream = new FileOutputStream(file2); InputStream inputStream = zipFile.getInputStream(nextEntry); while (true) { int read = inputStream.read(bArr); if (read == -1) { break; } fileOutputStream.write(bArr, 0, read); } fileOutputStream.close(); inputStream.close(); } else { fzs.bKm(); zipInputStream.close(); return; } } } @Override // defpackage.fzp public final boolean bKj() { long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - this.gLc < 3000) { return "downloading".equals(this.gLd); } this.gLc = currentTimeMillis; this.gLi.bKe(); this.gLd = this.gLi.bKh(); long bKg = this.gLi.bKg(); if ("downloading".equals(this.gLd) && currentTimeMillis - bKg < 20000) { return true; } if ("downloading".equals(this.gLd)) { this.gLi.uG("unDownload"); } return false; } @Override // defpackage.fzp public final boolean bKk() { boolean z; if (this.gKY > this.gKZ) { this.gLa = true; z = true; } else { z = false; } if (z) { return false; } if ("downloaded".equals(this.gLi.bKh()) && this.gKX[0].exists()) { return true; } bKo(); return false; } @Override // defpackage.fzp public final czq bKl() { this.gKO = new czq(this.mActivity); c cVar = new c(this, (byte) 0); if (!this.gLa) { this.gKO.setMessage(R.string.public_text_to_speech_download_plugin_notify); this.gKO.setPositiveButton(R.string.public_download, SupportMenu.CATEGORY_MASK, cVar); } else { this.gKO.setMessage(R.string.public_text_to_speech_download_plugin_update_notify); this.gKO.setPositiveButton(R.string.public_text_to_speech_download_plugin_update, SupportMenu.CATEGORY_MASK, cVar); } this.gKO.setNegativeButton(R.string.public_cancel, cVar); return this.gKO; } /* access modifiers changed from: package-private */ public void bKm() { this.gLi.ad(System.currentTimeMillis()); } /* access modifiers changed from: package-private */ public void bKn() { if (this.gLf && this.gLg) { if (this.fGM == null) { this.fGM = new BroadcastReceiver() { /* class defpackage.fzs.AnonymousClass5 */ public final void onReceive(Context context, Intent intent) { if (fzs.this.gLh != null && fzs.this.gLh.isShowing()) { fzs.this.gLj = false; fzs.this.gLh.dismiss(); } if ("TTSPLUGIN_DOWNLOAD_COMPLETE_ERROR_ACTION".equals(intent.getAction()) && fzs.this.gLe != null) { fzs.this.gLe.run(); fzs.this.gLe = null; } } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("TTSPLUGIN_DOWNLOAD_COMPLETE_ACTION"); intentFilter.addAction("TTSPLUGIN_DOWNLOAD_COMPLETE_ERROR_ACTION"); this.mActivity.registerReceiver(this.fGM, intentFilter); } this.gLj = false; if (this.gLh != null && this.gLh.isShowing()) { this.gLh.dismiss(); } this.gLh = new czq(this.mActivity); this.gLh.setCanceledOnTouchOutside(false); this.gLh.setTitle(this.mActivity.getResources().getString(R.string.public_assistant_component_dialog_tips)); this.gLh.setView(this.mActivity.getLayoutInflater().inflate(R.layout.public_dialog_cycle_progress_layout, (ViewGroup) null)); this.gLh.setNegativeButton(R.string.public_cancel, new DialogInterface.OnClickListener() { /* class defpackage.fzs.AnonymousClass2 */ public final void onClick(DialogInterface dialogInterface, int i) { fzs.this.gLj = true; fzs.this.gLh.dismiss(); } }); this.gLh.setOnKeyListener(new DialogInterface.OnKeyListener() { /* class defpackage.fzs.AnonymousClass3 */ public final boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) { if (4 != i) { return false; } fzs.this.gLj = true; fzs.this.gLh.dismiss(); return true; } }); this.gLh.setOnDismissListener(new DialogInterface.OnDismissListener() { /* class defpackage.fzs.AnonymousClass4 */ public final void onDismiss(DialogInterface dialogInterface) { if (fzs.this.gLj) { fzs.this.eNP = null; if (fzs.this.gLe != null) { fzs.this.gLe.run(); fzs.this.gLe = null; } } fzs fzs = fzs.this; try { if (fzs.fGM != null && fzs.mActivity != null) { fzs.mActivity.unregisterReceiver(fzs.fGM); fzs.fGM = null; } } catch (Exception e) { e.printStackTrace(); } } }); this.gLh.show(); gcq.ch("yuyin_ready", this.ego); } } /* access modifiers changed from: package-private */ public void bKo() { for (int i = 0; i < this.gKX.length; i++) { if (this.gKX[i] != null && this.gKX[i].exists()) { this.gKX[i].delete(); } } } }